package com.donggua.aichebao.commonui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by Administrator on 2017-07-22.
 */

public class ShrinkTextView extends LinearLayout{
    private LinearLayout mitembar;
    private View mHideView = null;
    private ImageView Image;
    private String ShrinkViewText;
    public ShrinkTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ShrinkTextView);
        View view= LayoutInflater.from(context).inflate(R.layout.item_bar, this);
        ShrinkViewText = ta.getString(R.styleable.ShrinkTextView_ShrinkViewText);
//        this.mHideView = (LinearLayout)view.findViewById(R.id.itemBar_content);
        this.mitembar=(LinearLayout) view.findViewById(R.id.itembar);
        this.Image = (ImageView) view.findViewById(R.id.item_img_title);
        TextView titleTextView = (TextView) view.findViewById(R.id.itemBar_title);
        titleTextView.setText( ShrinkViewText);

        Image.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mHideView != null) {
                    if (mHideView.getVisibility() == View.GONE) {
                        mHideView.setVisibility(View.VISIBLE);
                        Image.setImageResource(R.mipmap.down_arrow);
                    } else {
                        mHideView.setVisibility(View.GONE);
                        Image.setImageResource(R.mipmap.right_arrow);
                    }
                }
            }
        });
    }

    public ShrinkTextView(Context context) {
        super(context);
        init(context);
    }

    private void init(Context context) {

    }

   public  void setHideView(View view){
        this.mHideView = view;
    }


//    public void setShow(boolean isShow) {
//        if (isShow) {
//            mHideView.setVisibility(View.VISIBLE);
//            Image.setImageResource(R.mipmap.right_arrow);
//        } else {
//            mHideView.setVisibility(View.GONE);
//            Image.setImageResource(R.mipmap.down_arrow);
//        }
//    }

}

